home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / asc.sha / asc.c
C/C++ Source or Header  |  1991-04-12  |  1KB  |  53 lines

  1. /* The crc routine is from _KERMIT_-_A_File_Transfer_Protocol_ by *
  2.  * Frank da Cruz, Digital Press, 1987. P. 257.                    *
  3.  * The rest is public domain; -JimC.                              *
  4.  * This is the final version; the 3rd to get posted.              */
  5. #include <stdio.h>
  6.  
  7. main(argc, argv)
  8. int argc;
  9. char **argv;
  10. {
  11.   FILE *infile, *outfile;
  12.   int count=0, c=0, hi=0, low=0;
  13.   unsigned short value=0, dofx=0;
  14.  
  15.   argc--, argv++;
  16.   if (argc > 0) 
  17.     infile = fopen(*argv, "r");
  18.   else
  19.     infile = stdin;
  20.   argc--, argv++;
  21.   if (argc > 0)
  22.     outfile = fopen(*argv, "w");
  23.   else
  24.     outfile = stdout;
  25.  
  26.   for (count=8; count>0; count--)
  27.     c=getc(infile);
  28.  
  29.   fprintf(outfile,"%%%%HP: T(3)A(R)F(.);\n\"");
  30.  
  31.   while( (c=getc(infile)) != EOF ) {
  32.     value = c;
  33.     count +=1;
  34.  
  35.     dofx = (dofx >> 4) ^ (((value ^ dofx) & 0xf) * 0x1081);
  36.     dofx = (dofx >> 4) ^ ((((value >> 4) ^ dofx) & 0xf) * 0x1081);
  37.  
  38.     fprintf(outfile,"%2.2X",c);
  39.  
  40.     if (! (count % 32)) 
  41.       fprintf(outfile,"\n");
  42.   }
  43.   dofx &= 0xffff;
  44.  
  45.   for (count = 1; count < 4; count++) {
  46.     fprintf(outfile,"%1.1X",dofx & 0xf);
  47.     dofx >>= 4;
  48.     }
  49.   fprintf(outfile,"\"\n");
  50. }
  51.  
  52. /*   @(#)James H. Cloos, Jr.  */
  53.